<div>
    <div class='map_div'>
        <form  action='/home/company/submit' method="post" id='form'>
            <input type='hidden' name='id' value='<?php echo $company['id'];?>'>
            <div class='form-group row'>
                <label for="exampleInputName2">公司名称:</label>
                <input type="text" class="form-control" name='name' placeholder="" value="<?php echo $company['name'];?>"/>
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2">负责人:</label>
                <input type="text" class="form-control" name='person' placeholder="" value="<?php echo $company['person'];?>"/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">电话:</label>
                <input type="text" class="form-control" name='tel' placeholder="" value="<?php echo $company['tel'];?>"/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">所在地:</label>
                省：<select name="province" id="province" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($provinces as $k=>$v){
                        if($company['province'] == $v['provinceid']){
                            echo '<option id="province_'.$v['provinceid'].'" value="'.$v['provinceid'].'" selected="selected">'.$v['province'].'</option>';
                        }else{
                            echo '<option id="province_'.$v['provinceid'].'" value="'.$v['provinceid'].'">'.$v['province'].'</option>';
                        }
                    }?>
                </select>&nbsp;&nbsp;&nbsp;
                市：<select name="city" id="city" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($cities as $k=>$v){
                        if($company['city'] == $v['cityid']){
                            echo '<option id="city_'.$v['cityid'].'" value="'.$v['cityid'].'" selected="selected">'.$v['city'].'</option>';
                        }else{
                            echo '<option id="city_'.$v['cityid'].'" value="'.$v['cityid'].'">'.$v['city'].'</option>';
                        }
                    }?>
                </select>&nbsp;&nbsp;&nbsp;
                区：<select name="area" id="area" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($areas as $k=>$v){
                        if($company['area'] == $v['areaid']){
                            echo '<option id="area_'.$v['areaid'].'" value="'.$v['areaid'].'" selected="selected">'.$v['area'].'</option>';
                        }else{
                            echo '<option id="area_'.$v['areaid'].'" value="'.$v['areaid'].'">'.$v['area'].'</option>';
                        }
                    }?>
                </select>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">公司地址:</label>
                <input onblur='codeAddress(false);' type="text" class="form-control" id='address' name='address' placeholder="" value="<?php echo $company['address'];?>"/>
            </div>
             <div class='form-group row'>
                <label for="exampleInputName2" class="_label">公司简介:</label>
                <?php if(!empty($company)){?>
                <textarea name='intro' id="_intro" class="_textarea"><?php echo $company['intro']; ?></textarea>
                <?php }else{?>
                <textarea name='intro' id="_intro" class="_textarea"></textarea>
                <?php }?>
             </div>
            <div class="form-group login_sub">
                <input type="submit" class="btn btn-info" name="submit" value="提交">
            </div>
        </form>
    </div>
</div>
<script type='text/javascript'>
    $(document).ready(function () {
        $("#form").validate({
            rules: {
                name: {
                    required: true,
                },
                province:{
                    required: true,
                    number:true,
                },
                city:{
                    required: true,
                    number:true,
                },
                area:{
                    required: true,
                    number:true,
                },
                address: {
                    required: true,
                },
                person: {
                    required: true,
                },
                tel: {
                    required: true,
                },
            },
            messages: {
                name: {
                    required: '请输入店铺名称',
                },
                province:{
                    required: "请选择省",
                    number:"请选择省",
                },
                city:{
                    required: "请选择市",
                    number:"请选择市",
                },
                area:{
                    required: "请选择区",
                    number:"请选择区",
                },
                address: {
                    required: '请输入店铺地址',
                },
                person: {
                    required: '请输入联系人姓名',
                },
                tel: {
                    required: '请输入联系人电话',
                },
            }
        });
    });
 codeAddress();
$('#province').change(function(){
        var province = $('#province').val();
        $.ajax({
            url:"/home/Store/getcities?id="+province,
            async:true,
            success:function(data){
                if(data == "false"){
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>--请选择--</option>";
                $(data).each(function(i){
                    str += "<option id='city_"+this.cityid+"' value='"+this.cityid+"'>"+this.city+"</option>";
                });
                $('#city').html(str);
                $('#area').html("<option value='0'>--请选择--</option>");
            }
        });
    });
    $('#city').change(function(){
        var city = $('#city').val();
        $.ajax({
            url:"/home/Store/getareas?id="+city,
            async:true,
            success:function(data){
                if(data == "false"){
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>--请选择--</option>";
                $(data).each(function(i){
                    str += "<option id='area_"+this.areaid+"' value='"+this.areaid+"'>"+this.area+"</option>";
                });
                $('#area').html(str);
            }
        });
    });
    function codeAddress(bool) {
        var province = $("#province").val();
        if(province==0){
            return ;
        }
        privonce = $('#province_'+province).html();
        var city = $("#city").val();
        city = $('#city_'+city).html();
        if(city=='市辖区' || city=='县'){
            city = '';
        }
        var area = $("#area").val();
        area = $('#area_'+area).html();
        var str = privonce+','+city+','+area;
        var address = document.getElementById("address").value;
        if(bool == false){
        address = str+address;
        }else{
            address = str;
        }
    }
</script>